#pragma once

#ifndef _Mesh_h_
#define _Mesh_h_

#include "Collideable.h"
#include "D3DXMesh.h"
#include "DrawableGameComponent.h"
#include "../d3d/d3dUtility.h"

#include <vector>

namespace Framework {

class Mesh :
            public DrawableGameComponent, public Collideable {
public:
    Mesh(Game* game);
    virtual ~Mesh(void);
    virtual d3d::BoundingBox* GetBoundingBox();
    virtual d3d::BoundingSphere* GetBoundingSphere();
    D3DCULL GetCullMode() const;
    void SetCullMode(D3DCULL val);
    D3DXMesh* GetMesh() const;
    void SetMesh(D3DXMesh* val);
    virtual D3DXVECTOR3 GetPosition() const;
    virtual void SetPosition(D3DXVECTOR3 val);
    virtual D3DXVECTOR3 GetRotation() const;
    virtual void SetRotation(D3DXVECTOR3 val);
    virtual D3DXVECTOR3 GetScale() const;
    virtual void SetScale(D3DXVECTOR3 val);
    virtual D3DXMATRIX GetWorldMatrix();
    void SetEffectFile(LPCSTR effectFile);
    void SetMeshFile(LPCSTR meshFile);
    virtual void Draw(FLOAT timeDelta);
    virtual void Draw2(D3DXMATRIX* matrix);
    virtual void Initialize();
    virtual void LoadContent();
    virtual void UnloadContent();
    virtual void Update(FLOAT timeDelta);
protected:
    d3d::BoundingBox* boundingBox;
    bool boundingBoxNeedsUpdate;
    d3d::BoundingSphere* boundingSphere;
    bool boundingSphereNeedsUpdate;
    D3DCULL cullMode;
    ID3DXEffect* effect;
    LPCSTR effectFile;
    D3DXVECTOR3 position;
    D3DXMesh* mesh;
    LPCSTR meshFile;
    D3DXVECTOR3 rotation;
    D3DXVECTOR3 scale;
    D3DXMATRIX worldMatrix;
    D3DXMATRIX rotationMatrix;
    bool worldMatrixNeedsUpdate;
    virtual void DrawSubset(DWORD attribId);
    void LoadEffect();
    void LoadMesh();
};

}

#endif
